package hua.mtreader.feature.bookshelf.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import hua.mtreader.R;

/**
 * Created by Administrator on 2017/3/15.
 */

public class BookshelfTopView extends RelativeLayout {


    private ImageView ivFour;
    private ImageView ivThird;
    private ImageView ivTwo;
    private ImageView ivOne;
    private ImageView ivIcon;
    private TextView tvName;
    private RelativeLayout rlRencentBg;

    public BookshelfTopView(Context context) {
        super(context);
        init();
    }

    public BookshelfTopView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public BookshelfTopView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }




    private void init() {
        // setWillNotDraw(false);
        View.inflate(getContext(), R.layout.bookshelf_top, this);
        assignViews();

    }

    private void assignViews() {
        rlRencentBg = (RelativeLayout) findViewById(R.id.rl_rencent_bg);
        ivFour = (ImageView) findViewById(R.id.iv_four);
        ivThird = (ImageView) findViewById(R.id.iv_third);
        ivTwo = (ImageView) findViewById(R.id.iv_two);
        ivOne = (ImageView) findViewById(R.id.iv_one);
        ivIcon = (ImageView) findViewById(R.id.iv_icon);
        tvName = (TextView) findViewById(R.id.tv_name);
    }






    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);


    }

    private void initBg(Canvas canvas) {
        int centerX = getMeasuredWidth() / 2;
        int centerY = getMeasuredHeight() / 2;

        Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.bookshelf_top_bg);
        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.bookshelf_top_icon);
        Paint paint = new Paint();
        canvas.drawBitmap(bg,0,0, paint);

        int iconX = centerX - icon.getWidth() / 2;
        int iconY = centerY - icon.getHeight() / 2;
        canvas.drawBitmap(icon,iconX,iconY, paint);

        paint.setTextSize(14);
        paint.setColor(Color.WHITE);
        String text = "最近阅读";
        Rect bounds = new Rect();
        paint.getTextBounds(text,0,text.length(),bounds);
    }

    public RelativeLayout getRlRencentBg() {
        return rlRencentBg;
    }

    public void setRlRencentBg(RelativeLayout rlRencentBg) {
        this.rlRencentBg = rlRencentBg;
    }
}

















